#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
ll a[N], p[N], c[N];
ll A[N], B[N];
ll gcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
bool f(ll& A, ll& B, ll a, ll b, ll c) {
  ll x, y;
  ll d = gcd(a, b, x, y);
  if (c % d) return false;
  x %= b / d;
  if (x < 0) x += b / d;
  x = (__int128_t)x * c / d % (b / d);  // x = x0 + b / d * t
  // mn x satisfied a * x + b * y = c
  if (x <= 0) x += b / d;
  if ((__int128_t)a * x < c)
    x += (c - a * x + b / d * a - 1) / (b / d * a) * (b / d);
  A = x, B = b / d;
  return true;
}
ll crt() {
  ll a1 = A[1], b1 = B[1];
  rep(i, 2, n) {
    ll x, y;
    ll a2 = A[i], b2 = B[i];
    if (a1 > a2) swap(a1, a2), swap(b1, b2);
    ll c = a2 - a1;
    ll d = gcd(b1, b2, x, y);
    if (c % d) return -1;
    x = (__int128_t)x * c / d % (b2 / d);
    a1 = ((__int128_t)x * b1 + a1) % (b1 / d * b2);
    b1 = b1 / d * b2;
    if (a1 < 0) a1 += b1;
  }
  rep(i, 1, n) {
    if (A[i] > a1) a1 += (A[i] - a1) / b1;
  }
  return a1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    multiset<ll> st;
    cin >> n >> m;
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, n) cin >> p[i];
    rep(i, 1, n) cin >> c[i];
    rep(i, 1, m) {
      ll x;
      cin >> x;
      st.insert(x);
    }
    bool fail = false;
    rep(i, 1, n) {
      auto it = st.upper_bound(a[i]);
      if (it != st.begin()) it = prev(it);
      if (!f(A[i], B[i], *it, p[i], a[i])) {
        fail = true;
        break;
      }
      st.erase(it);
      st.insert(c[i]);
    }
    if (fail) {
      cout << -1 << endl;
    } else {
      ll ans = crt();
      cout << ans << endl;
    }
  }
  return 0;
}